<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %><%--
  Created by IntelliJ IDEA.
  User: 君未洋
  Date: 2021/5/4
  Time: 11:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>foreach</title>
</head>
<body>
<%--模拟for循环--%>
<c:forEach begin="1" end="10" var="i" step="1" varStatus="s">
    <%--这里的begin是开始值
    end是结束值
    var是定义循环变量名
    step是每次自增多少
    varStatus有2个方法,count表示循环次数,index元素的索引--%>
    ${i}<br>
</c:forEach>
<hr>
<%--模拟增强for循环--%>
<%
    List list = new ArrayList();
    list.add("aa");
    list.add("bb");
    list.add("cc");
    request.setAttribute("list", list);
%>
<c:forEach items="${list}" var="str" varStatus="s">
    ${s.index}.(${s.count}) ${str}<br>
</c:forEach>
</body>
</html>
